Helper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 8

2 Functions

Rating   Name   Duplication   Size   Complexity  
A dec2bin 0 16 3
A totalTrueInputs 0 13 5
1
import InvalidInputError from './InvalidInputError';
2
3
export default class Helper {
4
    static dec2bin(number, propositions) {
5 15
        if (!Number.isInteger(number)) {
6 6
            throw new InvalidInputError(number, 'number isnt a number');
7
        }
8
9 9
        if (!Number.isInteger(propositions)) {
10 4
            throw new InvalidInputError(
11
                propositions,
12
                'propositions isnt a number'
13
            );
14
        }
15
16 5
        const binary = parseInt(number, 10).toString(2);
17
18 5
        return binary.padStart(propositions, '0');
19
    }
20
21
    static totalTrueInputs(row) {
22 133
        if (!Array.isArray(row)) {
23 4
            throw new InvalidInputError(row, 'row isnt an array');
24
        }
25
26 129
        if (row.length < 1) {
27 1
            return 0;
28
        }
29
30 128
        return row.reduce(
31 288
            (accumulator, currentValue) => accumulator + (currentValue ? 1 : 0)
32
        );
33
    }
34
}
35